<?php
namespace Home\Controller;

use Common\Controller\ControllerController;


/**
 * 前台公共控制器
 * 为防止多分组Controller名称冲突，公共Controller名称统一使用模块名
 * @author jry <598821125@qq.com>
 */
class UserController extends HomeController
{
    /**
     * 用户登录检测
     * @author jry <598821125@qq.com>
     */
    public function index() {
        $this->is_login();
        $this->display();
    }

    public function jumpprice($user_info) {
        header('Location: http://wx.intable.net/wecha/');
    }

    public function login() {
        $user_model = D('Admin/User');
        if (IS_POST) {
            $data = format_data();
            $user_info = $user_model->login($data['username'],$data['password']);
            if ($user_info) {
                $user_model->auto_login($user_info);
                $this->jumpprice($user_info);
            }else{
                $this->error($user_model->getError());
            }

        }else{
            $uid = $user_model->is_login();
            if ($uid) {
                $user_info = $user_model->find($uid);
                $user_model->auto_login($user_info);
                $this->jumpprice($user_info);

            }else{
                $this->display();
            }
        }
    }

    public function register() {
        if (IS_POST) {
            $user_object = D('Admin/User');
            $data        = $user_object->create();
            if ($data) {
                $id = $user_object->add($data);
                if ($id) {
                    $this->success('注册成功，审核通过后即可使用', U('/Home/index'));
                } else {
                    $this->error('注册失败');
                }
            } else {
                $this->error($user_object->getError());
            }
        }else{
            $this->display();
        }
    }



}
